<template>
  <uni-popup ref="dialogRef" type="dialog" class="popup-agreement">
    <view class="box-wrap">
      <view class="title-wrap">用户协议提示</view>
      <view class="info-wrap">
        <view>
          您使用本应用服务前需仔细阅读并同意
          <span class="text" @tap="tapAgreement">《用户协议》</span>
          ，当您点击同意并继续，即表示您已理解并同意协议内容。
        </view>
      </view>
      <view class="btn-wrap">
        <button class="btn btn1" @tap="hide">取消</button>
        <button
          v-if="typeLogin === 2"
          hover-class="none"
          open-type="getPhoneNumber"
          @getphonenumber="bindPhoneNumber"
          class="btn btn2">
          同意并接受
        </button>
        <button v-else class="btn btn2" @tap="tapConfirm">同意并接受</button>
      </view>
    </view>
  </uni-popup>
</template>
<script lang="ts" setup>
const dialogRef = ref();

const tapAgreement = () => {
  const url = `${import.meta.env.VITE_VUE_APP_RES}${
    import.meta.env.VITE_VUE_APP_AGREEMENT
  }agreement-user.html`;
  uni.navigateTo({
    url: `/pagesMain/webView/webView?url=${url}`,
  });
};
const typeLogin = ref(0);

const show = (type: number) => {
  typeLogin.value = type;
  dialogRef.value?.open();
};
const hide = () => {
  dialogRef.value?.close();
};
const emit = defineEmits(['set-agreement']);
const tapConfirm = () => {
  hide();
  emit('set-agreement');
};
const bindPhoneNumber = (e: any) => {
  hide();
  emit('set-agreement', e);
};

defineExpose({
  show,
  hide,
});
</script>

<style lang="scss">
.popup-agreement {
  .box-wrap {
    margin: 0 20px;
    background-color: #fff;
    border-radius: 16px;
  }
  .title-wrap {
    line-height: 22px;
    font-size: 16px;
    padding: 24px 17px 14px 17px;
  }

  .info-wrap {
    display: flex;
    flex-direction: column;
    padding: 0 24px;
    max-height: 40vh;
    .text {
      color: $uni-color-primary;
      cursor: pointer;
    }
  }

  .btn-wrap {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 24px 0 27px 0;

    .btn {
      box-sizing: border-box;
      width: 114px;
      height: 38px;
      margin: 0 6px;
      font-size: 14px;
      border: 1px solid #d5d5d5;
      border-radius: 50px;
      display: flex;
      justify-content: center;
      align-items: center;
    }

    .btn1 {
      color: #545454;
      background-color: #fff;
    }

    .btn2 {
      color: #fff;
      border-color: $uni-color-primary;
      background-color: $uni-color-primary;
    }
  }
}
</style>